package com.qf.mq;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.StrategyExecutor;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 何星宇
 * @version V1.0
 * @Date 2021/11/23 9:43
 */

@Component
public class PreSendQueueListener {

    //注入策略链控制器
    @Autowired
    private StrategyExecutor strategyExecutor;

    @RabbitListener(queues = {RabbitMQConstants.TOPIC_PRE_SEND})
    public void consume(StandardSubmit standardSubmit , Channel channel, Message message) throws IOException {
        //获取消息
        System.out.println(standardSubmit);
        //执行策略
        strategyExecutor.execute(standardSubmit);

        //对消息进行ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

}
